//
//  ShareView.m
//  quxiangtao
//
//  Created by HHuajiang on 2018/12/18.
//  Copyright © 2018 shanhaijin. All rights reserved.
//

#import "ShareView.h"

@implementation ShareView

- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = WhiteColor;
        UILabel *shareLabel = [[UILabel alloc] init];
        shareLabel.text = @"一键图文分享到";
        shareLabel.font = Font(30);
        shareLabel.textColor = Color999999;
        [self addSubview:shareLabel];
        [shareLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.top.mas_equalTo(Margin);
        }];
        
        UIView *leftlllll = [[UIView alloc] init];
        leftlllll.backgroundColor = Colordddddd;
        [self addSubview:leftlllll];
        [leftlllll mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(Margin);
            make.right.equalTo(shareLabel.mas_left).offset(-Margin);
            make.centerY.equalTo(shareLabel.mas_centerY);
            make.height.mas_equalTo(0.5);
        }];
        
        UIView *rightllll = [[UIView alloc] init];
        rightllll.backgroundColor = Colordddddd;
        [self addSubview:rightllll];
        [rightllll mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-Margin);
            make.left.equalTo(shareLabel.mas_right).offset(Margin);
            make.centerY.equalTo(shareLabel.mas_centerY);
            make.height.mas_equalTo(0.5);
        }];
        
        NSArray *imageArray = @[@"微信", @"朋友圈", @"qq", @"QQ空间"];
        NSArray *titleArray = @[@"微信", @"朋友圈", @"QQ", @"空间"];
        for (int i = 0 ; i < titleArray.count; i ++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.tag = 1001+i;
            [self addSubview:button];
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(WIDTH/4*i);
                make.top.equalTo(shareLabel.mas_bottom).offset(jisuan(50));
                make.size.mas_equalTo(CGSizeMake(WIDTH/4, jisuan(150)));
                make.bottom.mas_equalTo(-20);
            }];

            UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageArray[i]]];
            [button addSubview:img];
            [img mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(0);
                make.centerX.equalTo(button.mas_centerX);
                make.size.mas_equalTo(CGSizeMake(jisuan(80), jisuan(80)));
            }];

            UILabel *titleLabel = [[UILabel alloc] init];
            titleLabel.font = Font(30);
            titleLabel.textColor = Color999999;
            titleLabel.text = titleArray[i];
            [button addSubview:titleLabel];
            [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(img.mas_bottom).offset(jisuan(25));
                make.centerX.equalTo(button.mas_centerX);
            }];
            
            [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        }
        
    }
    return self;
}

- (void)buttonClick:(UIButton *)button {
    
    switch (button.tag-1001) {
        case 0:
        {
            [self shareImageToPlatformType:UMSocialPlatformType_WechatSession];
        }
            break;
        case 1:
        {
            [self shareImageToPlatformType:UMSocialPlatformType_WechatTimeLine];
        }
            break;
        case 2:
        {
            [self shareImageToPlatformType:UMSocialPlatformType_QQ];
        }
            break;
        case 3:
        {
            [self shareImageToPlatformType:UMSocialPlatformType_Qzone];
        }
            break;
            
        default:
            break;
    }
    
}

- (void)shareImageToPlatformType:(UMSocialPlatformType)platformType{
    if (self.shareImageBlock) {
        self.shareImageBlock(platformType);
    }
}

@end
